﻿using System;
using Looptribe.Moodlin8.ViewModel;
using Looptribe.WinRT.Toolkit.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;

namespace Looptribe.Moodlin8.UIHelper
{
    public class EventBackgroundConverter : IValueConverter
    {
        public Brush AssignmentBrush { get; set; }
        public Brush CourseBrush { get; set; }
        public Brush UserBrush { get; set; }
        public Brush DefaultBrush { get; set; }

        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value == null)
                throw new ArgumentNullException("value");
            var eventValue = value as ICalendarEvent;
            if (eventValue == null)
                throw new ArgumentException("Value must be a ICalendarEvent.", "value");

            var e = eventValue as EventWrapper;
            if (e != null)
            {
                switch (e.WrappedObject.ModuleName)
                {
                    case "assign":
                        return AssignmentBrush;
                    default:
                        switch (e.Type)
                        {
                            case "course":
                                return CourseBrush;
                            case "user":
                                return UserBrush;
                        }
                        break;
                }
            }

            return DefaultBrush;
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotSupportedException();
        }
    }
}
